const {Op, Sequelize}=require('sequelize');
const{findF}=require('../utils/tool')
const{pwd,database,dialect,uid,host}=require('../config/index')
const fiels=findF('./model')
let obj={};
obj.Op=Op;


let db=new Sequelize(database,uid,pwd,{
    host:host,
    dialect:dialect
})
fiels.forEach(file=>{
    let tmpObj=require('../model/'+file);
    let ori=file.replace('.js','');
    let low=ori.toLowerCase();

    obj[ori]=db.define(low,tmpObj,{
        tableName:'app_'+low,
        charset:'utf8'
    })
})
obj.sync=async (force)=>{
    if(force){
        return db.sync({force:true})
    }
    return db.sync();
}

module.exports=obj
